<?php

namespace App\Shop\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * App\Shop\Models\Extension
 *
 * @property int $id
 * @property string $name
 * @property string $version
 * @property int $is_enabled
 * @property array|null $options
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|Extension newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Extension newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Extension query()
 * @method static \Illuminate\Database\Eloquent\Builder|Extension whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Extension whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Extension whereIsEnabled($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Extension whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Extension whereOptions($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Extension whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Extension whereVersion($value)
 * @mixin \Eloquent
 */
class Extension extends Model
{
    protected $fillable = ['name', 'is_enabled', 'version', 'options'];

    protected $casts = [
        'options' => 'json',
    ];

    /**
     * {@inheritDoc}
     */
    public function __construct(array $attributes = [])
    {
        $this->init();

        parent::__construct($attributes);
    }

    protected function init()
    {
        $connection = config('shop.database.connection') ?: config('database.default');

        $this->setConnection($connection);

        $this->setTable(config('shop.database.extensions_table') ?: 'shop_extensions');
    }
}
